package top.linyuxb.lycloud.admin.repository;

import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import top.linyuxb.lycloud.admin.entity.LyConfServerEntity;

import java.util.List;

/**
 * Created by Intellij IDEA.
 *
 * @Author: linyuxb
 * @Date: 2024/7/29 14:58
 * @Desc:
 */
@Repository
public interface LyConfServerRepository extends BaseRepository<LyConfServerEntity, Long> {
    /**
     * 通过环境全量查询
     *
     * @param env
     * @return
     */
    List<LyConfServerEntity> findByEnvOrderByIdDesc(String env);

    /**
     * 通过环境服务全量查询
     *
     * @param env
     * @param app
     * @return
     */
    List<LyConfServerEntity> findByEnvAndAppOrderByIdDesc(String env, String app);

    /**
     * 编辑服务状态
     *
     * @param id
     * @param status
     * @param weight
     */
    @Modifying
    @Transactional
    @Query(value = "UPDATE ly_conf_server SET status = ?2, weight = ?3 WHERE id = ?1 ", nativeQuery = true)
    void editServer(Long id, Integer status, Integer weight);
}
